<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    const formatSize = size=>{
        if(typeof +size !== 'number'){
            throw new Error('Argument(s) is illegal !');
        }
        const unitsHash = 'B,KB,MB,GB'.split(',')
        let index = 0
        while (size>1024&&index<unitsHash.length){
            size /= 1024
            index ++
        }
        return Math.round(size*100)/100+unitsHash[index]
    }
    formatSize('10240')
    formatSize('10240000')
</script>